import java.awt.event.*;
import javax.swing.*;

public class MoveToThisButton extends JButton{
	//	Local Variables
	private JFrame _parentFrame;
	private StoreLogic _logic;
	private QueuePanel _queueP;
	private FloorPanel _somethingP;
	
	public MoveToThisButton(JFrame aParentFrame, StoreLogic alogic, QueuePanel aQueueP, FloorPanel aSomethingP)
	{
		super("Move to selected queue");
		_parentFrame = aParentFrame;
		_logic = alogic;
		_queueP = aQueueP;
		_somethingP = aSomethingP;
		this.addActionListener(new MoveToThisListener());
	}
	
	private class MoveToThisListener implements ActionListener 
	{
		public void actionPerformed(ActionEvent e) 
		{	// checks if the store has any customers out on the floor
			if (_logic.getNotInLine().isEmpty())
			{
				JOptionPane.showMessageDialog(_parentFrame, "There are no customers in the store.","Error", 1);
			}	// checks if the user has selected a customer
			else if (_somethingP.getSelectedCustomer() < 0)
			{
				JOptionPane.showMessageDialog(_parentFrame, "You have not selected a customer.","Error", 1);
			}	// checks if the selected line is closed
			else if (!_logic.getLineStatus(_queueP.getSelectedQueue()))
			{
				JOptionPane.showMessageDialog(_parentFrame, "Cant move this customer to a closed queue.","Error", 1);
			}
			else
			{
				_logic.moveCustToQueue(_somethingP.getSelectedCustomer(), _queueP.getSelectedQueue());
			}
		}
	}
}
